package com.hbnu.exercise.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class DatabaseDemo05
{
    public static void main(String[] args)
    {
        try
        {
            Class.forName("com.mysql.cj.jdbc.Driver");

            String url = "jdbc:mysql://localhost:3306/class2210?serverTimezone=GMT&useSSL=false&characterEncoding=utf-8";
            String user = "root";
            String pwd = "123456";

            Connection connection = DriverManager.getConnection(url, user, pwd);

            String sql = "UPDATE tb_user SET salary = ? WHERE id = ?";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);

            preparedStatement.setDouble(1, 200);
            preparedStatement.setInt(2, 2);
            int row = preparedStatement.executeUpdate();

            preparedStatement.setDouble(1, 400);
            preparedStatement.setInt(2, 3);
            row = preparedStatement.executeUpdate();

            preparedStatement.close();
            connection.close();
        } catch (Exception e)
        {
            throw new RuntimeException(e);
        }

    }
}
